package airthmetic.exercise.hash;

import java.util.HashSet;

public class _3_无重复字符的最长子串 {
    public static int lengthOfLongestSubstring(String s) {
        if(s == null || s.length() == 0){
            return 0;
        }
        int max = 0;
        HashSet<Character> set = new HashSet<Character>();
        int left = 0;
        int right = 0;
        while(right < s.length()){
            while(set.contains( s.charAt(right))){
                set.remove(s.charAt(left));
                left++;
            }
            set.add( s.charAt(right));
            right++;
            max = Math.max(max, set.size());



        }
        return max;
    }

    public static void main(String[] args) {
        String s = "pwwkew";
        int i = lengthOfLongestSubstring(s);
        System.out.println(i);
    }
}
